﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Wicresoft.Common;
using Monthly.Framework.BusinessLogic;

public partial class Page_DeptList : BaseAuthenticationPage
{
    public string SearchClauseList
    {
        get
        {
            if (ViewState["SearchClauseList"] == null)
                ViewState["SearchClauseList"] = "1=1";
            return ViewState["SearchClauseList"].ToString();
        }
        set
        {
            ViewState["SearchClauseList"] = value;
        }
    }

    protected DataTable dtMonthlyList
    {
        get
        {
            if (ViewState["dtMonthlyList"] == null)
                ViewState["dtMonthlyList"] = new DataTable();
            return ViewState["dtMonthlyList"] as DataTable;
        }
        set
        {
            ViewState["dtMonthlyList"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "部门管理";
        ShowAdvancedSearch = false;

        if (!IsPostBack)
        {
            this.Order.OrderColumn = "CreateTime";
            this.Order.OrderDirection = "DESC";
            BindData();


        }
    }

    protected override void Pager_PageChanged(object sender, EventArgs e)
    {
        BindData();
        base.Pager_PageChanged(sender, e);
    }

    protected override void Order_OrderChanged(object sender, EventArgs e)
    {
        BindData();
        base.Order_OrderChanged(sender, e);
    }

    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindData();
    }

    protected void lbtnDelete_Click(object sender, EventArgs e)
    {

        ArrayList aldtMonthlyList = new ArrayList();

        int deleteCount = 0;
        for (int i = 0; i < rptFiles.Items.Count; i++)
        {
            if ((rptFiles.Items[i].FindControl("cbFiles") as CheckBox).Checked)
            {
                string id = dtMonthlyList.Rows[rptFiles.Items[i].ItemIndex][MonthlyDB.Entity.Monthly.SQLCOL_ID].ToString();
                aldtMonthlyList.Add(id);
                deleteCount++;
            }
        }
        BLMonthly.DeleteDepts((string[])aldtMonthlyList.ToArray(typeof(string)));

      
        BindData();
    }

    private void BindData()
    {
        int recordCount = 0;
        dtMonthlyList = BLMonthly.GetDeptList(SearchClauseList, Pager.PageIndex, Pager.PageSize, string.Format("{0} {1}", this.Order.OrderColumn, this.Order.OrderDirection), ref recordCount);
        Pager.RecordCount = recordCount;
        rptFiles.DataSource = dtMonthlyList;
        rptFiles.DataBind();
    }
    public string Cut(object title, int length)
    {
        if (title != null)
        {
            string _title = title.ToString();
            return _title.Length > length ? (_title.Substring(0, length) + "...") : _title;
        }
        return string.Empty;
    }

}

